const app = getApp()
const {
  baseURL
} = require('../../../fetch/http')
const api = require('../../../fetch/api')
Page({
  data: {
    navLeftItems: [],
    navRightItems: [],
    curIndex: 0,
    goods_classify_id:'',
    list:[]
  },
   onLoad() {
    this.classify()
  },

  async classify() {
    let res = await  api.goodsClassify()
    this.setData({
      navLeftItems: res.data,
      goods_classify_id:res.data[0].id
    })
    this.goods()
  },

  
  async goods() {
    let res = await api.goodsClassify({
      parent_id:this.data.goods_classify_id
    })
    this.setData({
      list:res.data
    })

  
  },
  goodsDetail(e) {
    const {id} = app.dataSet(e)
    let routes = getCurrentPages();
    let curRoute = routes[0] 
    curRoute.setData({
      goods_classify_id:id
    })
    wx.navigateBack({
      delta: 1,
    })
   
    // wx.navigateTo({
    //   url: '/pages/mall/goodsDetail/index?id=' + id,
    // })
  },

  //事件处理函数 
  switchRightTab: function (e) {
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    this.setData({
      curIndex: index,
      goods_classify_id:id
    })
    this.goods()
  }

})